﻿using MediatR;
using Warehouse.API.Applcation.Command.InjureCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.InjureCommandHandler
{
    /// <summary>
    /// 删除
    /// </summary>
    public class InjureDelCommandHandler : IRequestHandler<InjureDelCommand, int>
    {
        IInProductRepository IRep;

        public InjureDelCommandHandler(IInProductRepository IRep)
        {
            this.IRep = IRep;
        }

        public async Task<int> Handle(InjureDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await IRep.GetAllAsyns()).Where(c => request.InProductId.Contains(c.InProductId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await IRep.UpdateAsync(item);
            }
            return 1;
        }
    }
}
